import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-08-31
 * Time: 16:05
 */
public class TestSort {

    //插入排序的时间
    public static void insertSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort0(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序消耗的时间:"+(endTime-startTime));
    }
    //插入希尔排序的时间
    public static void shellSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellInset(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔插入排序消耗的时间:"+(endTime-startTime));
    }
    //选择排序的时间
    public static void selectSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序消耗的时间:"+(endTime-startTime));
    }
    //有序数组
    public static void orderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }

    }
    //无序数组
    public static void NotorderArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] =random.nextInt(10_0000);
        }

    }
    //测时间
    public static void main(String[] args) {
        int[] array = new int[10_0000];
        System.out.println("有序数组:");
        orderArray(array);
       insertSortTime(array);
        shellSortTime(array);
        selectSortTime(array);
        System.out.println("============");
        int[] array2 = new int[10_0000];
        System.out.println("无序数组:");
        NotorderArray(array2);
        shellSortTime(array2);
        insertSortTime(array2);
        selectSortTime(array2);

    }
    public static void main3(String[] args) {
        int[] array = {9,1,2,5,7,4,8,6,3,5};
        Sort insertSort = new Sort();
        insertSort.shellInset(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main2(String[] args) {
    int[] array = {112,1,56,43,7,56,15};
    Sort insertSort = new Sort();
    insertSort.insertSort0(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main1(String[] args) {
        int[] arr = {25,12,59,47,2,6};
//        InsertSort insertSort = new InsertSort(arr,arr.length);
//        insertSort.insertSort();
//        System.out.println(Arrays.toString(arr));
    }
}
